package Semester_2.src.Util_1;

import java.util.*;

public class poker {
    public static void main(String[] args) {
        super_Fighting_landlords();
    }
    public static void Fighting_landlords(){
        ArrayList<String> as=new ArrayList<String>();
        String []s={"♥","♣","♦","♠"};
        String []s1={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
        for(String s2:s){
            for(String s3:s1){
                as.add(s2+s3);
            }
        }
        as.add("大王");
        as.add("小王");
        Collections.shuffle(as);
        ArrayList<String> p1=new ArrayList<>();
        ArrayList<String> p2=new ArrayList<>();
        ArrayList<String> p3=new ArrayList<>();
        ArrayList<String> dp=new ArrayList<>();
        for(int i=0;i<as.size();i++){
            if(i>=as.size()-3){//最后三张牌留作底牌，放在底牌的数组内
                dp.add(as.get(i));
            }
            if(i%3==0){
                p1.add(as.get(i));
            }
            if(i%3==1){
                p2.add(as.get(i));
            }
            if(i%3==2){
                p3.add(as.get(i));//固定的算法，索引对玩家人数取余得到的余数个数就是玩家的人数，从0开始
            }
        }
        System.out.println(p1);
        System.out.println(p2);
        System.out.println(p3);
        System.out.println(dp);
    }
    public static void super_Fighting_landlords(){
        HashMap<Integer,String> his=new HashMap<Integer,String>();//用来储存牌组和编号的数组
        ArrayList<Integer> ai=new ArrayList<Integer>();//储存编号的数组
        TreeSet<Integer> p1=new TreeSet<Integer>();//玩家1
        TreeSet<Integer> p2=new TreeSet<Integer>();//玩家2
        TreeSet<Integer> p3=new TreeSet<Integer>();//玩家3
        TreeSet<Integer> dp=new TreeSet<Integer>();//底牌
        int index=0;
        String []s={"♥","♣","♦","♠"};
        String []s1={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        for(String s2:s1){//外层是数字内层是花色，就能做到按照数字排序，反过来就是按照花色排序
            for(String s3:s){
                his.put(index,s2+s3);
                ai.add(index);
                index++;
            }
        }
        his.put(index,"小王");
        ai.add(index);
        index++;
        his.put(index,"大王");
        ai.add(index);
        Collections.shuffle(ai);
//        for(int i=0;i<as.size();i++){
//            his.put(i,as.get(i));
//            ai.add(i);
//        }//添加元素
        //遍历元素,向每一个玩家发牌
        for(int i=0;i<ai.size();i++){
            if(i>=ai.size()-3){
                dp.add(ai.get(i));
            }else if(i%3==0){
                p1.add(ai.get(i));
            }else if(i%3==1){
                p2.add(ai.get(i));
            }else if(i%3==2){
                p3.add(ai.get(i));
            }
        }
        System.out.println(p1);
        System.out.println(p2);
        System.out.println(p3);
//        System.out.println(p1);
//        System.out.println(p2);
//        System.out.println(p3);
//        System.out.println(dp);
        superNested("玩家1",p1,his);
        superNested("玩家2",p2,his);
        superNested("玩家3",p3,his);
        superNested("底牌",dp,his);
    }
    public static void superNested(String name,TreeSet<Integer> ts,HashMap<Integer,String> his){
        System.out.println(name+"的牌是：");
        for(Integer i:ts){
            String s=his.get(i);
            System.out.print(s+" ");
        }
        System.out.println();
    }
}
